package com.photons.timesync

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.activity.viewModels
import androidx.databinding.DataBindingUtil
import com.photons.timesync.databinding.ActivityMainBinding
import com.photons.timesync.utils.NetUtils
import com.photons.timesync.viewmodel.TimeSyncViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
    private val mViewModel: TimeSyncViewModel by viewModels()
    private var mDataBinding: ActivityMainBinding? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

        mDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_main)
        title = getString(R.string.app_name) + " - " + NetUtils.getLocalIPv4()

        mDataBinding?.viewModel = mViewModel
        mDataBinding?.lifecycleOwner = this // 使用livedata绑定界面时，必设此项
    }

    fun onSyncClicked(view: View) {
        mViewModel.send(this)
    }
}